package com.gxa.eurekribbon.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RibbonConfiguration {
    // @LoadBalanced注解表明这个restRemplate开启负载均衡的功能

    @Bean
    IRule getRule(){
        return new RoundRobinRule();
    }

    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();    // Template:JdbcTemplate,RedisTemplate,
    }
}